Skip to content

Form: getHttpData() return type reflects the $htmlName argument#353

Open
jaroslavlibal wants to merge 1 commit into
nette:v3.2from
jaroslavlibal:getHttpData-return-type
Open

Form: getHttpData() return type reflects the $htmlName argument#353
jaroslavlibal wants to merge 1 commit into
nette:v3.2from
jaroslavlibal:getHttpData-return-type

Conversation

@jaroslavlibal

Copy link
Copy Markdown

The @return of Form::getHttpData() is not correct.

It says string|string[]|Nette\Http\FileUpload|null, but this only describes the call with a control name. There are two problems:

  1. When called without arguments, the method returns all form data. This is a nested array (the whole POST tree), not string[]. So PHPStan thinks the result is string[] and reports errors on nested access like $data['x']['y'].

  2. For one control, string[] is also not enough. A multi-file upload returns FileUpload[], not only string[].

This PR changes only the docblock to a conditional return type based on $htmlName:

@return ($htmlName is null ? mixed[] : string|string[]|Nette\Http\FileUpload|Nette\Http\FileUpload[]|null)

This probably replaces the older #333.

@jaroslavlibal jaroslavlibal changed the base branch from master to v3.3 June 25, 2026 10:04
@jaroslavlibal jaroslavlibal changed the base branch from v3.3 to v3.2 June 25, 2026 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getHttpData() PHPDoc typing values as string[], but the actual data can contain nested arrays

1 participant